#version 330

in vec3 normal;
in vec4 position;
in vec3 eye_normal;
in vec4 eye_position;
in vec4 color;

uniform vec4 attr_light0_color;
uniform vec3 attr_light0_vec;
uniform vec4 attr_light1_color;
uniform vec3 attr_light1_vec;
uniform float attr_material_ambient;
uniform vec4 attr_ambient;
uniform float attr_colorscale;

//~ out vec4 FragColor;
const float scale = 0.3;




void main()
     
 {
    // Correct the surface normal for interpolation effects
     
     vec4 gamma_color = color;
     gamma_color.r = pow(gamma_color.r, 2);
     gamma_color.g = pow(gamma_color.g, 2);
     gamma_color.b = pow(gamma_color.b, 2);
     
     
     vec3 normal2 = normalize(normal);
     
     // Fetch all textures.
     // Begin view-space light calculations
     float ldist,lattenv,langle,lshad;
     vec4 lcolor,lspec,lpoint,latten,ldir,leye;
     vec3 lvec,lhalf;
     vec4 tot_ambient = vec4(0,0,0,0);
     vec4 tot_diffuse = vec4(0,0,0,0);
     tot_ambient += attr_ambient;
     // Directional Light 0
     lcolor = attr_light0_color;
     lspec  = lcolor;
     lvec   = normalize(attr_light0_vec);
     lcolor *= clamp(dot(normal2, -lvec), 0.0, 1.0);
     tot_diffuse += lcolor;
     // Directional Light 1
     lcolor = attr_light1_color;
     lspec  = lcolor;
     lvec   = normalize(attr_light1_vec);
     lcolor *= clamp(dot(normal2, -lvec), 0.0, 1.0);
     tot_diffuse += lcolor;
     //~ // Begin view-space light summation
     vec4 result = vec4(0,0,0,0);
     result += tot_ambient * attr_material_ambient;
     result += tot_diffuse * gamma_color;
     result = clamp(result, 0.0, 1.0);
     result *= attr_colorscale;
     // End view-space light calculations
     
     
     
     //~ result *= gamma_color;
     //~ FragColor = result * 1.000001;
     
     
     
     result.r = pow(result.r, 0.5);
     result.g = pow(result.g, 0.5);
     result.b = pow(result.b, 0.5);
     //~ gl_FragColor = result * 1.000001;
     gl_FragData[0] = result * 1.000001;
     //~ gl_FragData[0] = lcolor;
     //~ gl_FragData[0] = vec4(normal2, 0);
     //~ gl_FragData[1] = vec4(0, attr_colorscale, 0, 1);
     gl_FragData[1] = vec4(0, 0, 0, 0);
}
